import 'package:flutter/material.dart';
import 'package:get/get.dart';

import '../controllers/following_controller.dart';
import '../widgets/cartoon_list_item.dart';
import '../widgets/empty_view.dart';
import '../widgets/error_view.dart';
import '../widgets/loading_view.dart';

class FollowingPage extends StatelessWidget {
  const FollowingPage({super.key});

  _onRetryLoadData() {
    print("retry~");
  }

  @override
  Widget build(BuildContext context) {
    return GetBuilder(
      init: FollowingController(),
      builder: (controller) {
        return Scaffold(
          backgroundColor: Colors.white,
          appBar: AppBar(backgroundColor: Colors.white, title: const Text('我的关注')),
          body: Stack(
            children: <Widget>[
              ListView.builder(
                  itemCount: controller.cartoonList.length,
                  itemBuilder: (BuildContext context, int index) {
                    var cartoon = controller.cartoonList[index];
                    return CartoonListItem(cartoon: cartoon);
                  }),
              Offstage(offstage: !controller.isShowError, child: ErrorView(retryAction: _onRetryLoadData)),
              Offstage(offstage: !controller.isShowEmpty, child: const EmptyView()),
              Offstage(offstage: !controller.isLoading, child: const LoadingView()),
            ],
          ),
        );
      },
    );
  }
}
